import java.io.File;
import java.io.FileNotFoundException;

/**
 * receives files from frontend and calls needed methods
 * @author cerko
 *
 */
public class Dispatcher {
	
	private OutputManager outputManager;
	
	private BiBLoader bibLib;
	private RefEvaluator evaluator;
	private RefAnalyzer analyzer;
	private OutputManager output;
	private RefDecoder decoder;
	
	public Dispatcher(){
		
	}
	
	/**
	 * cast na formatovanie z BiBTexu
	 * @param texInput
	 * @param texOutput
	 * @param bib
	 * @param format
	 * @throws FileNotFoundException
	 */
	public void insertRefs(File texInput, File texOutput, File bib, File format) throws FileNotFoundException{
		
		
		bibLib = new BiBLoader(bib);
		analyzer = new RefAnalyzer();
		evaluator = new RefEvaluator(bibLib);
		output = new OutputManager(texOutput, format, evaluator.assignData(analyzer.getUsedRefs(texInput)));
		output.writetoFile();
	}
	
	/**
	 * cast na reformatovanie referenciu z TeX s inputformatom do TeX-u s outputFormatom
	 * @param texInput
	 * @param texOutput
	 * @param inputFormat
	 * @param outputFormat
	 */
	public void reformatRefs(File texInput, File texOutput, File inputFormat, File outputFormat){
		decoder = new RefDecoder();
		
		output = new OutputManager(texOutput, outputFormat, decoder.referencesToBib(texInput, inputFormat));
		output.writetoFile();
	}
	
	/**
	 * cast na ulozenie referencii z TeXu s inputformatom do BiBTeXu
	 * @param texInput
	 * @param texOutput
	 * @param inputFormat
	 */
	public void saveIntoBibTex(File texInput, File texOutput, File inputFormat){
		decoder = new RefDecoder();
		output = new OutputManager(texOutput, decoder.referencesToBib(texInput, inputFormat));
		output.saveAsBib();
	}
	
}
